<?php

/*
 * This class is used for as Model for Quotationimages table 
 */

class Model_Quotationimages extends Model_Base {

    protected $_name = 'tbl_quotation_images';
    protected $_primaryKey = 'qni_id';

    /**
     * Fetch an individual entry with the quotation id
     *
     * @param  int|string $id
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchEntryById($id) {
        $select = $this->select()
                ->from(array('quotation' => 'tbl_quotation_images'))
                ->where('qn_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    /**
     *  This function is used to get quotations
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchQuotationimagess($where = "", $limit = "", $offset = "0", $order = 'qni_id', $sort = 'ASC') {
        $select = $this->select()
                ->from(array('quotation' => 'tbl_quotation_images'));
        if ($where != '') {
            $select->where($where);
        }
        if ($limit != "") {
            $select->limit($limit, $offset);
        }
        $select->order($order . " " . $sort);
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    /**
     *  This function is used to get total orders
     * @return int
     */
    public function getQuotationimagesCount($where) {
        $select = $this->select()
                ->from(array('quotation' => 'tbl_quotation_images'), Array('cnt' => 'count(*)'));
        if ($where != '') {
            $select->where($where);
        }
        $rows = parent::fetchRow($select);
        return($rows->cnt);
    }

}
